package com.pla;

import com.pla.persistence.Vine;
import com.pla.persistence.VineDao;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class VineDetailActivity extends Activity {

	public static final String DATA_KEY_VINE_ID = "com.pla.vineid";
	private final VineDao vineDao = new VineDao();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.vinedetail);

		if (!getIntent().getExtras().containsKey(DATA_KEY_VINE_ID)) {
			Log.e("com.pla", "Cant start detail activity - no vine id.");
			finishActivity(RESULT_CANCELED);
		}

		long id = getIntent().getExtras().getLong(DATA_KEY_VINE_ID);
		Vine vine = vineDao.loadVine(id);

		if (null == vine) {
			Log.e("com.pla", "Cant found vine with id " + id);
			finishActivity(RESULT_CANCELED);
		}

		show(vine);
	}

	private void show(Vine vine) {
		TextView name = (TextView) findViewById(R.id.TextView02);
		name.setText(vine.getName());
	}
}
